<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>车辆出租</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/resources/css/public.css" media="all" />
</head>
<body class="childrenBody">

<!-- 查询条件开始-->
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form" method="post" id="searchFrm">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">车牌号:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="carnumber"  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">车辆类型:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="cartype"  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">车辆价格:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="startPrice"  autocomplete="off" class="layui-input" placeholder="请输入最低价格">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="endPrice"  autocomplete="off" class="layui-input" placeholder="请输入最高价格">
                    </div>
                </div>
            </div>


            <div  class="layui-form-item" style="text-align: center;">
                <div class="layui-input-block" >
                    <button type="button" class="layui-btn layui-btn-normal  layui-icon layui-icon-search" lay-submit lay-filter="doSearch">查询</button>
                    <button type="reset" class="layui-btn layui-btn-warm  layui-icon layui-icon-refresh">重置</button>
                </div>
            </div>
        </form>
    </blockquote>
</form>
<!-- 查询条件结束-->


<!-- 数据表格开始 -->
<div>
    <table class="layui-hide" id="carTable" lay-filter="carTable"></table>

    <div id="carRowBar" style="display: none;">
        <button type="button" lay-event="renCar" class="layui-btn layui-btn-warm layui-btn-xs">
            <span class="layui-icon layui-icon-edit"></span>出租汽车
        </button>
        <button type="button" lay-event="viewImage" class="layui-btn layui-btn-xs">
            <span class="layui-icon layui-icon-search"></span>查看大图
        </button>
    </div>
</div>
<!-- 数据表格结束 -->

<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 20px" id="addOrUpdateDiv" >
    <form class="layui-form layui-row layui-col-space10"  lay-filter="dataFrm" id="dataFrm">
        <div class="layui-col-md12 layui-col-xs12">
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md8 layui-col-xs7">
                    <div class="layui-form-item magt3">
                        <label class="layui-form-label">车牌号:</label>
                        <div class="layui-input-block">
                            <input type="text" name="carnumber" class="layui-input" lay-verify="required" readonly>
                        </div>
                    </div>
                    <div class="layui-form-item magt3">
                        <label class="layui-form-label">车辆类型:</label>
                        <div class="layui-input-block">
                            <input type="text" name="cartype" class="layui-input" lay-verify="required" readonly>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">租车时间:</label>
                        <div class="layui-input-block">
                            <input type="text" name="begindate" id="rentdate" class="layui-input" readonly lay-verify="required" placeholder="请选择租车时间">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4 layui-col-xs5">
                    <div class="layui-upload-list thumbBox mag0 magt3" id="carimgDiv">
                        <!-- 显示上传的图片 -->
                        <img class="layui-upload-img thumbImg" id="showCarImg" src="/file/showImages/images/defaultimg.jpg">
                    </div>
                </div>
            </div>
            <div class="layui-form-item magb0">
                <label class="layui-form-label">身份证号码:</label>
                <div class="layui-input-block">
                    <input type="text" name="identity"  class="layui-input" lay-verify="required" placeholder="请输入身份证号码">
                </div>
            </div>
            <div class="layui-form-item magb0" style="margin-top:20px;">
                <div class="layui-inline">
                    <label class="layui-form-label">租赁天数:</label>
                    <div class="layui-input-block">
                        <input type="text" name="rentday" id="rentday" class="layui-input" lay-verify="required|number" placeholder="请输入租赁天数">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">出租价格:</label>
                    <!-- 租金 -->
                    <input type="hidden" id="rentprice" name="rentprice">

                    <div class="layui-input-block">
                        <input type="text" name="price" id="totalPrice" class="layui-input" lay-verify="required|number" readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item magb0" style="margin-top:20px;text-align: center;">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-icon layui-icon-release" lay-filter="doSubmit" lay-submit="">提交</button>
                    <button type="reset" class="layui-btn layui-btn-warm layui-btn-sm layui-icon layui-icon-refresh" >重置</button>
                </div>
            </div>
        </div>
    </form>
</div>
<!--查看图片大图-->
<div id="viewCarImagerDiv" style="display:none;text-align: center;">
    <img alt="出租图片" width="550" height="350" id="view_carimg">
</div>
<!-- 添加和修改的弹出层结束 -->


<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery','form','table','layer','laydate'],function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var  laydate=layui.laydate;

        //初始化时间选择器
        laydate.render({
            elem:'#rentdate',
            type:'datetime'
        });

        tableIns=table.render({
            elem: '#carTable'
            , url: '/bus/car/list?isrenting=0'  //只查询未出组
            , toolbar: '#carToolBar' //开启头部工具栏，并为其绑定左侧模板
            , page: true
            ,height:"full-180"
            , title: '车辆数据表'
            , cols: [ [
                {type: 'checkbox'}
                , {field: 'id', title: '编号编号', align: 'center'}
                , {field: 'carnumber', title: '车牌号码', align: 'center'}
                , {field: 'cartype', title: '车辆类型', align: 'center'}
                , {field: 'color', title: '车辆颜色', align: 'center'}
                , {field: 'price', title: '购买价格', align: 'center'}
                , {field: 'rentprice', title: '出租价格', align: 'center'}
                , {field: 'deposit', title: '出租押金', align: 'center'}
                , {field: 'isrenting', title: '出租状态', align: 'center', templet: function (d) {
                        return d.isrenting == '1' ? '<font color=blue>已出租</font>' : '<font color=red>未出租</font>';
                    }
                }
                , {field: 'carimg', title: '缩略图', align: 'center',templet: function (d) {
                        return "<img src='/file/showImages/"+d.carimg+"'/>";
                    }
                }
                , {field: 'createtime', title: '录入时间', align: 'center'}
                , {fixed:'right',title: '操作', toolbar: '#carRowBar',width:200}
            ] ],
            done: function (res, curr, count) {
                //判断当前页面是否大于1并且当前页的数据为0
                if (curr > 1 && res.data.length == 0) {
                    var pageValue = curr - 1
                    //刷新数据表格
                    tableIns.reload({
                        page: {curr: pageValue}
                    });
                }
            }
        });

        //监听表单提交事件
        form.on("submit(doSearch)",function (data) {
            tableIns.reload({
                url:'/bus/car/list?isrenting=0',
                where:data.field,
                page:{
                    curr:1
                }
            });
            return false;
        });




        //监听行工具栏事件
        table.on('tool(carTable)',function (obj) {
            switch (obj.event) {
                case 'renCar':
                    //打开头部工具栏添加公告的窗口
                    openRentCarWindow(obj.data);
                    break;
                case 'viewImage':
                    viewImageCar(obj.data);
                    break
            }
        })





        var mainIndex;//打开窗口的索引
        var url;//提交请求的地址




        /**
         * 修改部门
         */
        function  openRentCarWindow(data){
            mainIndex= layer.open({
                type:1,
                content:$('#addOrUpdateDiv'),
                area:["800px","500px"],
                title:"出租车辆",
                success:function () {
                    //表单数据回显
                    form.val("dataFrm",data);
                    //清空表单数据
                    $("#rentdate").val("");//租车时间
                    $('[name="identity"]').val("");//身份证号码
                    $("#rentday").val("");//租赁天数
                    $("#totalPrice").val("");//租金

                    //车辆的缩略图设置一个默认图片
                    $(".thumbImg").attr("src","/file/showImages/"+data.carimg);
                    //提交数据
                    url="/bus/rent/addRent";
                }

            })
        }


        /**
         * 查看大图
         * @param data
         */
      function viewImageCar(data){
            mainIndex= layer.open({
                type:1,
                content:$('#viewCarImagerDiv'),
                area:["800px","500px"],
                title:"【"+data.carnumber+'】的出租图片',
                area:['600px','400px'],
                success:function (index) {
                    //车辆的缩略图设置一个默认图片
                    $("#view_carimg").attr("src","/file/showImages/"+data.carimg);
                }

            })

      }

      //租赁天数失去焦点时,计算价格天数乘以单价
        $("#rentday").blur(function () {
            //获取天数
            var day=$(this).val();
            if (day.length>0){
                //汽车租金
                var rentprice=$("#rentprice").val();
                //总金额
                $("#totalPrice").val(day * rentprice);
            }else {
                $("#totalPrice").val("");
            }
        })


        //监听表单提交事件
        form.on("submit(doSubmit)",function (data) {
            $.post(url, data.field, function (result) {
                if (result.success){
                    //提示信息
                    layer.msg(result.message,{icon:1})

                    tableIns.reload();

                    layer.close(mainIndex);

                }else {
                    layer.msg(result.message,{icon:2});
                }
            }, "json");
            //禁止页面跳转
            return false;
        })


    });


</script>



</body>
</html>